package Action;

import org.apache.struts2.interceptor.validation.SkipValidation;

import com.opensymphony.xwork2.ModelDriven;

import Dao.AdminDao;
import DaoImpl.AdminDaoImpl;
import Entity.Admin;
import Service.AdminService;

public class AdminAction extends SuperAction implements ModelDriven<Admin>{
	
	private static final long serialVersionUID = 1L;
	private Admin admin = new Admin();
	
	public void validate()
    {
     	if("".equals(admin.getAdminid().trim()))
     	{
     		this.addFieldError("adminnameError","请填写用户名");
     	}
     	if(admin.getAdminpwd().length()<6)
     	{
     		this.addFieldError("passwordError","密码小于6位");
     	}
     		
    }
	@SkipValidation
	public String logout()
	{
		if (session.getAttribute("loginAdminName") != null)
		{
			session.removeAttribute("loginAdminName");
		}
		return "logout_success";
	}
	public String login() {
		System.out.println("login");
		AdminDao adao = new AdminDaoImpl();
		Admin admin1 = adao.adminLogin(admin);
		if (admin1 != null) {
			session.setAttribute("loginAdmin", admin1);
			return "loginAdmin_success";
		}
		else {
			System.out.println("admin1 == null");
			return "loginAdmin_failure";
		}
		
	}
	
	public Admin getModel() {
		return this.admin;
	}

}
